package com.java.baseconversion;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

/**
 * 进制的转换: 字节转换成16进制
 * 使用jdk自带的MessageDigest(消息摘要+MD5)进行加密
 * @author wangning
 * @create 2020-11-30 15:58
 */
public class TestBaseConversion01 {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        String a = "a";
        System.out.println("Arrays.toString(a.getBytes()) = " + Arrays.toString(a.getBytes()));
        String s = "123456";
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] bytes = md.digest(s.getBytes());
//        byte[] bytes = s.getBytes();
        for (byte aByte : bytes) {
            String hexstr = Integer.toHexString(0xFF & aByte);
            if (hexstr.length() == 1) {
                hexstr = "0" + hexstr;
            }
            System.out.print(hexstr);
        }
    }

}
